home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWMemory / Include / FWMemHlp.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  5.1 KB  |  156 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMemHlp.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWMEMHLP_H
  11. #define FWMEMHLP_H
  12.  
  13. #ifndef FWCOMMON_H
  14. #include "FWCommon.h"
  15. #endif
  16.  
  17. #ifndef FWEXCLIB_H
  18. #include "FWExcLib.h"
  19. #endif
  20.  
  21. #if FW_LIB_EXPORT_PRAGMAS
  22. #pragma lib_export on
  23. #endif
  24.  
  25. //========================================================================================
  26. // CLASS FW_CAcquireLockedSystemHandle
  27. //
  28. //    A resource acquisition helper object for locking a system handle within a scope.
  29. //========================================================================================
  30.  
  31. class FW_CLASS_ATTR FW_CAcquireLockedSystemHandle FW_AUTO_DESTRUCT_OBJECT
  32. {
  33. public:
  34.     FW_CAcquireLockedSystemHandle(FW_PlatformHandle aSystemHandle);
  35.     virtual ~ FW_CAcquireLockedSystemHandle();
  36.     
  37.     void* GetPointer() const;
  38.     
  39. private:
  40.     FW_CAcquireLockedSystemHandle(const FW_CAcquireLockedSystemHandle& acquireObject);
  41.     FW_CAcquireLockedSystemHandle& operator=(const FW_CAcquireLockedSystemHandle& acquireObject);
  42.         // Copy constructor and assignment operator not valid for this class.
  43.  
  44.     FW_PlatformHandle    fLockedSystemHandle;
  45.     void*                 fLockedPointer;
  46. };
  47.  
  48. //----------------------------------------------------------------------------------------
  49. // FW_CAcquireLockedSystemHandle::GetPointer
  50. //----------------------------------------------------------------------------------------
  51.  
  52. inline void* FW_CAcquireLockedSystemHandle::GetPointer() const
  53. {
  54.     return fLockedPointer;
  55. }
  56.  
  57. //========================================================================================
  58. // CLASS FW_CAcquireTemporarySystemHandle
  59. //
  60. //    A resource acquisition helper object for allocating and locking a system handle
  61. //  within a scope.  You can transfer ownership of the handle by calling OrphanPointer.
  62. //========================================================================================
  63.  
  64. class FW_CLASS_ATTR FW_CAcquireTemporarySystemHandle FW_AUTO_DESTRUCT_OBJECT
  65. {
  66. public:
  67.     FW_CAcquireTemporarySystemHandle(unsigned long size);
  68.     virtual ~ FW_CAcquireTemporarySystemHandle();
  69.     
  70.     void                 Resize(unsigned long newSize);
  71.     
  72.     void*                 Orphan();
  73.     FW_Boolean             IsOrphan() const;
  74.     
  75.     FW_PlatformHandle    GetPlatformHandle() const;
  76.     void*                 GetPointer() const;
  77.     
  78. private:    
  79.     FW_PlatformHandle     fTemporarySystemHandle;
  80.     void*                 fMemoryPointer;
  81.     FW_Boolean             fFree;                        // If TRUE, the dtor will free the fMemory
  82.  
  83. private:
  84.     FW_CAcquireTemporarySystemHandle(const FW_CAcquireTemporarySystemHandle& acquireObject);
  85.     FW_CAcquireTemporarySystemHandle& operator=(const FW_CAcquireTemporarySystemHandle& acquireObject);
  86.         // Copy constructor and assignment operator not valid for this class.
  87. };
  88.  
  89. //----------------------------------------------------------------------------------------
  90. // FW_CAcquireTemporarySystemHandle::GetPointer
  91. //----------------------------------------------------------------------------------------
  92.  
  93. inline void* FW_CAcquireTemporarySystemHandle::GetPointer() const
  94. {
  95.     return fMemoryPointer;
  96. }
  97.  
  98. //----------------------------------------------------------------------------------------
  99. // FW_CAcquireTemporarySystemHandle::GetPlatformHandle
  100. //----------------------------------------------------------------------------------------
  101.  
  102. inline FW_PlatformHandle FW_CAcquireTemporarySystemHandle::GetPlatformHandle() const
  103. {
  104.     return fTemporarySystemHandle;
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. // FW_CAcquireTemporarySystemHandle::Orphan
  109. //----------------------------------------------------------------------------------------
  110.  
  111. inline void* FW_CAcquireTemporarySystemHandle::Orphan()
  112. {
  113.     FW_ASSERT(fFree == TRUE);
  114.     fFree = FALSE;
  115.     return fMemoryPointer;
  116. }
  117.  
  118. //----------------------------------------------------------------------------------------
  119. // FW_CAcquireTemporarySystemHandle::IsOrphan
  120. //----------------------------------------------------------------------------------------
  121.  
  122. inline FW_Boolean FW_CAcquireTemporarySystemHandle::IsOrphan() const
  123. {
  124.     return !fFree;
  125. }
  126.  
  127. #ifdef FW_BUILD_MAC
  128. //========================================================================================
  129. // CLASS FW_CMacAcquireMultiFinderHeapZone
  130. //
  131. //    A resource acquisition helper object to set the current heap zone to be the multifinder
  132. //    heap zone. This is very useful for example with QuickTime.
  133. //========================================================================================
  134.  
  135. class FW_CLASS_ATTR FW_CMacAcquireMultiFinderHeapZone FW_AUTO_DESTRUCT_OBJECT
  136. {
  137. public:
  138.     FW_CMacAcquireMultiFinderHeapZone();
  139.     virtual ~ FW_CMacAcquireMultiFinderHeapZone();
  140.     
  141. private:    
  142.     THz                 fOldHeap;
  143.  
  144. private:
  145.     FW_CMacAcquireMultiFinderHeapZone(const FW_CMacAcquireMultiFinderHeapZone& acquireObject);
  146.     FW_CMacAcquireMultiFinderHeapZone& operator=(const FW_CMacAcquireMultiFinderHeapZone& acquireObject);
  147.         // Copy constructor and assignment operator not valid for this class.
  148. };
  149. #endif
  150.  
  151. #if FW_LIB_EXPORT_PRAGMAS
  152. #pragma lib_export off
  153. #endif
  154.  
  155. #endif
  156.